package lock;
import java.util.concurrent.Semaphore;

public class FairReadWriteLock implements ReadWriteLock {

	private static final int MAX_THREAD = 1000;
	private Semaphore pv;

	public FairReadWriteLock() {
		pv = new Semaphore(MAX_THREAD, true);
	}

	public void readLock() throws InterruptedException {
		pv.acquire();
	}

	public void realseReadLock() {
		pv.release();
	}

	public void writeLock() throws InterruptedException {
		pv.acquire(MAX_THREAD);
	}

	public void realseWriteLock() {
		pv.release(MAX_THREAD);
	}

}
